#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V,s,d[100010],u[100010],a[100010],p[100010];
int f(int i)
{
	int num=u[i]*u[i]+2*a[i]*(p[m]-d[i]);
	int left=1,right=num;
	while(left<=right)
	{
		int mid=(left+right)/2;
		if(mid<=num/mid&&mid+1>num/(mid+1))
			return mid;
		if(mid<num/mid)
			left=mid+1;
		else
			if(mid>=num/mid)
				right=mid-1;
	}
	return -1;
}
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>T;
	while(T--)
	{
		int sum=0,k;
		cin>>n>>m>>L>>V;
		for(int i=1;i<=n;i++)
		{
			cin>>d[i]>>u[i]>>a[i];
			if(a[i]==0)
				k=1;
			if(a[i]>0)
				k=2;
		}
		for(int i=1;i<=m;i++)
			cin>>p[i];
		sort(p+1,p+m+1);
		if(k==1)
		{
			for(int i=1;i<=n;i++)
				if(u[i]>V&&p[m]>=d[i])
						sum++;
			if(sum!=0)
				cout<<sum<<" "<<m-1<<endl;
			else
				cout<<sum<<" "<<m<<endl;
		}
		if(k==2)
		{
			for(int i=1;i<=n;i++)
			{
				long long num=f(i);
				if(p[m]>=d[i]&&(num>V||(num==V&&num*num<u[i]*u[i]+2*a[i]*(p[m]-d[i]))))
					sum++;
			}
			if(sum!=0)
				cout<<sum<<" "<<m-1<<endl;
			else
				cout<<sum<<" "<<m<<endl;
		}
	}                       
	return 0;
}